<template>
	<view class="page">
		<view class="bar_info" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class="title_bar">
				<view class="title_bar_left" @tap.stop="handleJump" data-type="BACK">
					<image class="title_bar_left_icon" :src='STATIC_URL+"5.png"'></image>
				</view>
				<view class="title_bar_center">
					订单
				</view>
				<view class="title_bar_right"></view>
			</view>
		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		
		<!-- <view class="view_bg"></view> -->
		<!-- <u-tabs :list="tabList" bg-color="transparent" active-color="#3d3d3d" inactive-color="rgba(61,61,61,0.5)" :bar-style="barStyle" :is-scroll="false" :current="current" @change="change"></u-tabs> -->
		<u-sticky bg-color="transparent" :offset-top="88+StatusBarRpx">
			<u-tabs :list="tabList" bg-color="#f5f5f5" active-color="#3d3d3d" inactive-color="rgba(61,61,61,0.5)" gutter="20" :bar-style="barStyle" :is-scroll="true" :current="current" @change="change"></u-tabs>
		</u-sticky>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#41AF36"></u-loading>
			<view class="loading_text">加载中</view>
		</view>
		
		<view class="order_list" v-else>
			<view class="list_item" v-for="(item, index) in list" :key="index" @tap.stop="goDetails(item.status, item.id)">
				<view class="order_sn flex align-center justify-between">
					<view class="order_sn_le">订单号：{{item.order_no}}</view>
					<view class="order_sn_ri" v-if="item.status == 0">待受理</view>
					<view class="order_sn_ri" v-if="item.status == 1 || item.status == 2">
						<text v-if="!item.receipt_image">待收货</text>
						<text v-else>已收货</text>
					</view>
					<!-- <view class="order_sn_ri" v-if="item.status == 2">待收货</view> -->
					<view class="order_sn_ri_1" v-if="item.status == 3">异常订单</view>
					<view class="order_sn_ri" v-if="item.status == 4">已完成</view>
					<view class="order_sn_ri_1" v-if="item.status == 5">已取消</view>
					<view class="order_sn_ri_1" v-if="item.status == 6">已拒绝</view>
					<view class="order_sn_ri_1" v-if="item.status == 7">订单退款</view>
				</view>
				<view class="order_date">配送时间：{{item.dispatching_time}}</view>
				<view class="order_shop">
					<scroll-view class="shop_le" :scroll-x="true" >
						<view class="shop_le_img" v-for="(v, k) in item.goods" :key="k">
							<u-lazy-load :image="v.product_image" img-mode="aspectFill" height="140" border-radius="8"></u-lazy-load>
						</view>
						<view class="shop_le_img" style="margin-right: 0;"></view>
					</scroll-view>
					<view class="shop_ri">
						<view class="order_price" v-if="user.is_show_price == 1">￥{{Number(item.total_price)}}</view>
						<view v-else style="height: 18rpx;"></view>
						<view class="shop_num">共{{item.goods.length > 0 ? item.goods.length : 0}}种</view>
					</view>
				</view>
				<view class="remark_text" v-if="item.remark">备注：{{item.remark}}</view>
				<view class="create_time">下单时间：{{item.created_at}}</view>
				<view class="order_btn flex align-center justify-end">
					
					<view class="btn_view_1" v-if="item.status == 0 || item.status == 5" @tap.stop="delOrderInfo(item.id)">删除订单</view>
					
					<view class="btn_view"  @tap.stop="copyOrder(item.id)">复制订单</view>
					<view class="btn_view" v-if="item.status == 0" @tap.stop="cancelOrder(item.id)">取消订单</view>
					<view class="btn_view" v-if="(item.status == 1 || item.status == 2 || item.status == 3 || item.status == 7) && !item.receipt_image" @tap.stop="getOrderTake(item.id)">订单收货</view>
					<view class="btn_view" v-if="(item.status == 1 || item.status == 2 || item.status == 3 || item.status == 7) && item.receipt_image" @tap.stop="editReceiptImage(item.id, item.receipt_image)">已收货</view>
				</view>
			</view>
			<u-loadmore v-if="last_page > 1" class="loadmore" font-size="24" :status="status"
				:icon-type="iconType" :load-text="loadText" />
		</view>
		<view class="noData" v-if="list.length == 0 && !isShow">
			<image src="/static/empty/no.png"></image>
		</view>
		
		<!-- <view class="save_btn" @tap.stop="forgetPsd">确认修改</view> -->
		
		<u-popup v-model="popupShow1698293086456" border-radius="24" :mask="true" :mask-close-able="true" mode='center'>
			<!---删除历史记录弹窗flex布局开始-->
			<view class="flex flex-direction flex-wrap align-center search_flex_2">
				<text class='search_fd2_0'>提示</text>
				<text class='search_fd2_1'>确定取消该订单吗？</text>
				<view class='flex flex-wrap align-center search_fd2_2'>
					<view class='search_fd2_2_c0 flex align-center justify-center' @tap.stop="popupShow1698293086456=false">取消</view>
					<view class='search_fd2_2_c1 flex align-center justify-center' @tap.stop="confirmCancel()">确认</view>
				</view>
			</view>
		</u-popup>
		
		
		<u-popup v-model="del_show" border-radius="24" :mask="true" :mask-close-able="true" mode='center'>
			<!---删除历史记录弹窗flex布局开始-->
			<view class="flex flex-direction flex-wrap align-center search_flex_2">
				<text class='search_fd2_0'>提示</text>
				<text class='search_fd2_1'>确定删除该订单吗？</text>
				<view class='flex flex-wrap align-center search_fd2_2'>
					<view class='search_fd2_2_c0 flex align-center justify-center' @tap.stop="del_show=false">取消</view>
					<view class='search_fd2_2_c2 flex align-center justify-center' @tap.stop="confirmDel">确认</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		data() {
			return {
				popupShow1698293086456: false,
				del_show: false,
				tabList: [{
					name: '全部',
					id: ""
				}, {
					name: '待受理',
					id: 0
				}, {
					name: '待收货',
					id: 1
				}, {
					name: '已收货',
					id: 1
				}, {
					name: '异常',
					id: 3
				}, {
					name: '已取消',
					id: 5
				}, {
					name: '已完成',
					id: 4
				}, {
					name: '退货',
					id: 7
				}],
				order_status: "",
				current: 0,
				barStyle: {
					backgroundColor: '#41AF36',
					width: '46rpx',
					height: '8rpx'
				},
				image: '/static/index/3.png',
				user: {},
				
				list: [],
				"isShow": true,
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
			}
		},
		onLoad(options) {
			let {current, order_status} = options;
			if (current !== undefined) this.current = current;
			if (order_status !== undefined) this.order_status = order_status;
		},
		onShow() {
			this.user = global.userInfo;
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getOrder();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getOrder();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {
		
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getOrder();
			}, 500)
		},
		methods: {
			change(e) {
				this.current = e;
				this.order_status = this.tabList[this.current].id;
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getOrder();
			},
			getOrder() {
				let is_receipt_image = "";
				if (this.current == 2) {
					is_receipt_image = 0;
				} else if (this.current == 3) {
					is_receipt_image = 1;
				} else {
					is_receipt_image = "";
				}
				this.$api.get(global.apiUrls.gylOrder, {
					page: this.page,
					pageSize: 10,
					status: this.order_status,
					is_receipt_image: is_receipt_image
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 200) {
						this.last_page = res.data.data.pageInfo.totalPage;
						if (this.is_pull) {
							this.list = res.data.data.items;
						} else {
							this.list = this.list.concat(res.data.data.items);
						}
					} else {
						this.$message.info(res.data.message);
					}
				})
			},
			// 复制订单
			copyOrder(id) {
				this.$api.post(global.apiUrls.gylCopyOrder, {
					order_id: id
				}).then(res => {
					this.$message.info(res.data.message);
				})
			},
			// 取消订单  gylOrderCancel
			cancelOrder(id) {
				this.order_id = id;
				this.popupShow1698293086456 = true;
			},
			confirmCancel() {
				this.popupShow1698293086456 = false;
				this.$api.post(global.apiUrls.gylOrderCancel, {
					order_id: this.order_id
				}).then(res => {
					this.$message.info(res.data.message);
					if (res.data.code == 200) {
						this.page = 1;
						this.is_pull = true;
						this.isShow = true;
						this.getOrder();
					}
				})
			},
			delOrderInfo(id) {
				this.order_id = id;
				this.del_show = true;
			},
			confirmDel() {
				this.del_show = false;
				this.$api.post(global.apiUrls.gyldelOrder, {
					order_id: this.order_id
				}).then(res => {
					this.$message.info(res.data.message);
					if (res.data.code == 200) {
						this.page = 1;
						this.is_pull = true;
						this.isShow = true;
						this.getOrder();
					}
				})
			},
			// 订单收货  gylTake
			getOrderTake(id) {
				uni.navigateTo({
					url: '/pages/my/receiptCertificate?id=' + id + '&type=1'
				})
			},
			// 已收货修改收据单
			editReceiptImage(id, receipt_image) {
				global.receipt_image = receipt_image;
				uni.navigateTo({
					url: '/pages/my/receiptCertificate?id=' + id + '&type=2'
				})
				
			},
			goDetails(status, id) {
				if (status == 3 || status == 7) {
					uni.navigateTo({
						url: '/pages/my/returnDetails?order_no=' + id
					})
				} else {
					uni.navigateTo({
						url: '/pages/my/orderDetails?order_no=' + id
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: #f5f5f5;
		// background: url(https://www.shiyaocanyin.com/images/8.png) no-repeat #f5f5f5;
		// background-size: 100% auto !important;
		.bar_info {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 100;
			position: fixed;
			top: 0rpx;
			background: #f5f5f5;
			// background: url(https://www.shiyaocanyin.com/images/8.png) no-repeat;
			// background-size: 100% auto !important;
		
			.title_bar {
				padding: 0 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
		
				.title_bar_left {
					width: 50rpx;
					.title_bar_left_icon {
						width: 18rpx;
						height: 32rpx;
					}
				}
		
				.title_bar_center {
					line-height: 88rpx;
					font-size: 36rpx;
					font-weight: 400;
				}
		
				.title_bar_right {
					width: 50rpx;
				}
			}
		}
		
		.save_btn {
			width: 700rpx;
			height: 80rpx;
			background: #41AF36;
			border-radius: 50rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #fff;
			text-align: center;
			line-height: 80rpx;
			margin: 120rpx auto 0;
		}
	}
	.view_bg {
		width: 100%;
		height: 1000rpx;
		z-index: 0;
		position: fixed;
		top: 0rpx;
		background: url(https://www.shiyaocanyin.com/images/8.png) no-repeat #f5f5f5;
		background-size: 100% auto !important;
	}
	.order_list {
		padding: 30rpx 20rpx 16rpx;
		// position: relative;
		// z-index: 100;
		.list_item {
			background: #fff;
			border-radius: 10rpx;
			padding: 22rpx 0;
			margin-bottom: 20rpx;
			.order_sn {
				padding: 0 30rpx;
				.order_sn_le {
					font-weight: 500;
					font-size: 30rpx;
					color: #3D3D3D;
				}
				.order_sn_ri {
					font-weight: 400;
					font-size: 26rpx;
					color: #009824;
				}
				.order_sn_ri_1 {
					font-weight: 400;
					font-size: 26rpx;
					color: #E90000;
				}
			}
			.order_date {
				margin-top: 8rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: rgba(0,0,0,0.8);
				padding: 0 30rpx;
			}
			.order_shop {
				margin-top: 24rpx;
				position: relative;
				padding-left: 30rpx;
				.shop_le {
					white-space: nowrap;
					.shop_le_img {
						display: inline-block;
						width: 140rpx;
						height: 140rpx;
						border-radius: 8rpx;
						margin-right: 20rpx;
					}
					/deep/.u-lazy-item {
						width: 140rpx !important;
						height: 140rpx !important;
					}
				}
				.shop_ri {
					width: 140rpx;
					height: 140rpx;
					background: rgba(255,255,255,0.9);
					position: absolute;
					right: 0;
					top: 0;
					padding: 35rpx 14rpx 0 0;
					.order_price {
						text-align: right;
						font-weight: 500;
						font-size: 26rpx;
						color: #000000;
					}
					.shop_num {
						text-align: right;
						font-weight: 400;
						font-size: 22rpx;
						color: rgba(61,61,61,0.5);
					}
				}
			}
			.remark_text {
				margin-top: 12rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: rgba(0,0,0,0.8);
				padding: 0 30rpx;
			}
			.create_time {
				margin-top: 12rpx;
				font-weight: 400;
				font-size: 22rpx;
				color: rgba(0,0,0,0.5);
				padding: 0 30rpx;
			}
			.order_btn {
				padding: 0 30rpx;
				margin-top: 8rpx;
				.btn_view {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 140rpx;
					height: 60rpx;
					background: #41AF36;
					border-radius: 10rpx;
					font-size: 24rpx;
					color: #fff;
					margin-left: 20rpx;
				}
				.btn_view_1 {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 140rpx;
					height: 60rpx;
					background: #E92200;
					border-radius: 10rpx;
					font-size: 24rpx;
					color: #fff;
					margin-left: 20rpx;
				}
			}
		}
	}
	
	.codeLogin_fd1_1_c2 {
		font-size: 26rpx;
		color: #41AF36;
		font-weight: 500;
		margin-left: 30rpx;
	}
	
	
	.search_flex_2 {
		background: #fff;
		// margin: 0rpx 105rpx 0rpx 105rpx;
		border-radius: 25rpx 25rpx 25rpx 25rpx;
		padding: 40rpx 0rpx 0rpx 0rpx;
	}
	.search_fd2_2_c2 {
		background: transparent;
		line-height: 90rpx;
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		font-size: 32rpx;
		color: #E90000;
		width: 269rpx;
		height: 90rpx;
	}
	
	.search_fd2_2_c1 {
		background: transparent;
		line-height: 90rpx;
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		font-size: 32rpx;
		color: #41AF36;
		width: 269rpx;
		height: 90rpx;
	}
	
	.search_fd2_2_c0 {
		border-right: 1px solid #EEEEEE;
		background: transparent;
		line-height: 90rpx;
		border-radius: 0rpx 0rpx 0rpx 16rpx;
		font-size: 32rpx;
		color: #999;
		height: 90rpx;
		width: 270rpx;
	}
	
	.search_fd2_2 {
		border-top: 1px solid #eee;
	}
	
	.search_fd2_1 {
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		margin: 48rpx 0rpx 60rpx 0rpx;
	}
	
	.search_fd2_0 {
		color: #333333;
		font-size: 36rpx;
		font-weight: 500;
		line-height: 45rpx;
	}
</style>